//
//  NSObject+LKDBHelperEx.h
//  quickBatchManager
//
//  Created by 王定波 on 15/10/10.
//  Copyright © 2015年 jack. All rights reserved.
//

#import <Foundation/Foundation.h>

@interface NSObject(LKDBHelperEx)
+(double)sumWithWhere:(NSString*)key where:(id)where, ...;
+(NSMutableArray*)searchWithWhere:(id)where orderBy:(NSString*)orderBy groupBy:(NSString*)groupBy offset:(NSInteger)offset count:(NSInteger)count;

@end
@interface LKDBHelper(DatabaseExecuteEx)
- (id)modelValueWithProperty:(LKDBProperty *)property model:(NSObject *)model;
- (void)asyncBlock:(void (^)(void))block;

#pragma mark - row count operation
- (double)sum:(Class)modelClass key:(NSString*)key where:(id)where;

- (void)sum:(Class)modelClass where:(id)where key:(NSString*)key callback:(void (^)(NSInteger))callback;

- (double)sumWithTableName:(NSString *)tableName key:(NSString*)key where:(id)where;

// splice 'where' 拼接where语句
- (NSMutableArray *)extractQuery:(NSMutableString *)query where:(id)where;


// dic where parse
- (NSString *)dictionaryToSqlWhere:(NSDictionary *)dic andValues:(NSMutableArray *)values;
- (NSMutableArray *)executeResult:(FMResultSet *)set Class:(Class)modelClass tableName:(NSString *)tableName;
- (NSMutableArray *)executeOneColumnResult:(FMResultSet *)set;
- (void)sqlString:(NSMutableString *)sql groupBy:(NSString *)groupBy orderBy:(NSString *)orderby offset:(NSInteger)offset count:(NSInteger)count;
- (NSMutableArray *)searchBaseWithParams:(LKDBQueryParams *)params;
- (NSMutableArray *)searchBase:(Class)modelClass columns:(id)columns where:(id)where orderBy:(NSString *)orderBy  groupBy:(NSString*)groupBy offset:(NSInteger)offset count:(NSInteger)count;
- (NSMutableArray *)search:(Class)modelClass where:(id)where orderBy:(NSString *)orderBy groupBy:(NSString*)groupBy offset:(NSInteger)offset count:(NSInteger)count;

@end
